package com.lizhao.win007com.match.webapi.mapper;

import com.lizhao.win007com.commons.pojo.info.model.RelationInfo;
import com.lizhao.win007com.commons.pojo.match.model.Match;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface MatchMapper {
    //获取联赛数据
    @Select("SELECT * FROM `${table}` WHERE companyid=${companyid} ORDER BY matchdatetime DESC")
    List<Match> findList(@Param("table") String table,@Param("companyid") Integer companyid);

    //获取联赛数据
    @Select("SELECT * FROM `${table}` WHERE companyid=${companyid} AND season=${season} ORDER BY matchdatetime DESC LIMIT 200;")
    List<Match> findListBySeason(@Param("table") String table,@Param("companyid") Integer companyid, @Param("season") String season);

    //通过pageid、companyid获取联赛数据
    @Select("SELECT `begin`,`odds`,`end` FROM `${table}` WHERE companyid=${companyid} AND pageid=${pageid};")
    Match findListByTableAndCompanyIdAndPageId(@Param("table") String table, @Param("companyid") Integer companyid, @Param("pageid") Integer pageid);

    //获取总记录数
    @Select("SELECT COUNT(*) total FROM `${table}`;")
    Integer findTotal(String table);

    //通过id删除数据
    @Delete("DELETE FROM `${table}` WHERE id=#{id};")
    void deleteByTableAndId(@Param("table") String table,@Param("id") Integer id);

    //通过leagueid、code、season、companyid获取赛事数据
    @Select("SELECT * FROM `${table}` WHERE season='${season}' AND companyid=${companyid};")
    List<Match> findMatchByLeagueIdAndTableAndSeasonAndCompanyId(@Param("table") String table, @Param("season") String season, @Param("companyid") Integer companyid);

    //今日推荐赛事
    @Select("SELECT * FROM `${table}` WHERE companyid1=${companyid1} AND companyid2=${companyid2} AND " +
            "relationabs1='${relation}' AND season='${season}' ORDER BY matchdatetime;")
    List<RelationInfo> findRelationByLeagueIdAndCompanyIdAndSeasonAndRelation(@Param("table") String table,
                                                                              @Param("companyid1") Integer companyid1,
                                                                              @Param("companyid2") Integer companyid2,
                                                                              @Param("season") String season,
                                                                              @Param("relation") String relation);
}
